home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / NGL2.0.1J(ppc).sit / NGL2.0.1J(ppc) / Cel & Rotate Sample / Cel & Rotate Sample(PPC).c < prev    next >
C/C++ Source or Header  |  1996-10-03  |  3KB  |  133 lines

  1. /*============================================================
  2.  
  3.                     Cel & Rotate サンプルプログラム
  4.                     
  5. ============================================================*/
  6. #include        "N_Library.h"
  7.  
  8. short        Data_Rsrc = 0;
  9. long            total_step = 0;
  10. long            wait;
  11. short        i,r=0;
  12. short        x[128];
  13. short        y[128];
  14. short        rt[128];
  15. short        sp[128];
  16.  
  17. void main(void)
  18. {
  19.     WindowPtr    window;
  20.     Rect            BGrect;
  21.     short        p;
  22.  
  23.     ToolboxInit();
  24.     ColorCheck();
  25.     HideMenuBar();
  26.     window = GetNewWindow (128,nil,(WindowPtr)-1L );
  27.     N_Window_Set(window,-(window->portBits.bounds.left),-(window->portBits.bounds.top),640,480);
  28.      Open_Resource_File(128,1,&Data_Rsrc);
  29.     N_Sp_Make(640,480);                                                //スプライト・セルの表示範囲
  30.     N_Cel_Make2(640,480);                                                //N_Cel_Loop2 で処理を行う場合はこちらで初期化する
  31.     HideCursor();
  32.     N_Pict_Draw(128,0,0,(GrafPtr)Main_Window,true);
  33.     N_Sprite_Set(129,0,48,48,0,1,1,1);                                    //Sp 0 にパターンを登録(回転付きモード)
  34.     N_Sprite_Set(201,1,32,32,0,1,1,0);                                    //Sp 1 にパターンを登録(背景用)
  35.     N_Sprite_Set(202,2,32,32,0,1,1,0);                                    //Sp 2 にパターンを登録(背景用)
  36.     Delay(60,&wait);
  37.     Close_Resource_File(&Data_Rsrc);
  38.  
  39.     for (i=0;i!=128;i++)                                                    //128個分の初期位置・速度を配列に入れる
  40.     {
  41.         x[i] = GetRandom(0,640-48);
  42.         y[i] = GetRandom(0,640-48);
  43.         sp[i] = GetRandom(1,5)*2;
  44.         rt[i] = 0;
  45.     }
  46.  
  47.     do
  48.     {
  49.         SetPort((GrafPtr)SP_off);
  50.         SetRect(&BGrect,0,0,640,480);
  51.         ScrollRect(&BGrect,-32,0,nil);
  52.  
  53.         for(i=0;i!=15;i++)
  54.         {
  55.             p = GetRandom(0,1);
  56.             if (p==0)
  57.             {
  58.                 N_Sp_Put(0x80000000+1,608,i*32);
  59.             }
  60.             else
  61.             {
  62.                 N_Sp_Put(0x80000000+2,608,i*32);
  63.             }
  64.         }
  65.  
  66.         if (total_step<128)                                                //1番目の動きは右に移動していく動き
  67.         {
  68.             for (i=0;i!=48;i++)
  69.             {
  70.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],x[i]+24,y[i]+24,rt[i]);    //中心をそれぞれのパターンの真ん中に設定
  71.                 x[i] = x[i] + sp[i];
  72.                 if (x[i]>640)                                            //右端に行ったら、左に戻り y を変更
  73.                 {
  74.                     x[i] = -64;
  75.                 }
  76.             }
  77.         }
  78.  
  79.         if (total_step>=128 && total_step<256)                                //2番目の動きは、回転
  80.         {
  81.             for (i=0;i!=48;i++)
  82.             {
  83.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],320,240,r);            //(320,240)を中心に角度 r で回転
  84.             }
  85.             r+=8;                                                    //角度を動かす
  86.         }
  87.  
  88.         if (total_step>=256 && total_step<384)                                //3番目の動きは、回転 & 座標移動
  89.         {
  90.             for (i=0;i!=48;i++)
  91.             {
  92.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],300,220,r);            //(300,220)を中心に角度 r で回転
  93.                 x[i] = x[i] + sp[i];
  94.                 if (x[i]>640)                                            //右端に行ったら、左に戻り y を変更
  95.                 {
  96.                     x[i] = -64;
  97.                 }
  98.             }
  99.             r-=8;
  100.         }
  101.  
  102.         if (total_step>=384 && total_step<512)                                //4番目の動きは、それぞれの座標を中心にまわりながら右に移動
  103.         {
  104.             for (i=0;i!=48;i++)
  105.             {
  106.                 rt[i] = x[i]*4;
  107.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],x[i]+24,y[i]+24,rt[i]);    //中心をそれぞれのパターンの真ん中に設定
  108.                 x[i] = x[i] + sp[i];
  109.                 if (x[i]>640)
  110.                 {
  111.                     x[i] = -64;
  112.                 }
  113.             }
  114.         }
  115.  
  116.         if (total_step == 511)                                            //最初からループ
  117.         {
  118.             total_step =0;
  119.             r = 0;
  120.         }
  121.         N_Cel_Loop2(0,0);                                                //画面を更新(N_Sp_Makeで設定した範囲を指定の座標に転送)
  122.         total_step++;
  123.     }
  124.     while (!Button());
  125.     ShowMenuBar();
  126.     ShowCursor();
  127.     FlushEvents( everyEvent, 0 ); 
  128.     ColorRevert();
  129. }
  130.  
  131.  
  132.  
  133.